package com.zy.Conterller;


import com.zy.pojo.Delsupper;
import com.zy.service.DelsupperService;
import com.zy.vo.ResultVo;
import com.zy.vo.delSupper.DelsupperVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/delsupper")
public class DelsupperController {

    @Resource
    private DelsupperService delsupperService;
    @GetMapping("/pagelist/{pageSize}/{pageNo}")
    public ResultVo getDelsupperList(@PathVariable Integer pageSize, @PathVariable Integer pageNo, DelsupperVo delsupperVo){

        return ResultVo.success(delsupperService.getPage(pageNo,pageSize,delsupperVo));
    }

    @GetMapping("deletesupper/{id}")
    @RequiresPermissions("delsupper:del")
    public ResultVo del(@PathVariable String id){
        try {
            delsupperService.getdelsupper(Integer.parseInt(id));
            return ResultVo.success("删除成功!");
        }catch (Exception e){
            return ResultVo.fail("删除失败！！",e);
        }
    }

    @PostMapping("delrestore")
    @RequiresPermissions("delsupper:add")
    public ResultVo getdelsupperrestore(@RequestBody Delsupper delsupper){
        try {
            delsupperService.getdelsupperrestore(delsupper);
            delsupperService.getdelsupper(delsupper.getId());
            return ResultVo.success("还原联系人成功！");
        }catch (Exception e){
            return ResultVo.fail("还原联系人失败！");
        }
    }


}
